package cn.mylearn.sys.controller.user;

import java.sql.Timestamp;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.core.Controller;

import cn.mylearn.tools.encryption.ShiroEncryption;
import cn.mylearn.tools.uuid.UuidFormat;

/**
 * @author FenLg
 *
 */
public class SysUserController extends Controller{

	public void index() {
		
	}
	
	/**
	 * @描述: 新增或编辑
	 *
	 * @时间: 2017年11月20日 下午3:18:53 
	 * 
	 * @版本: V1.0
	 */
	public void add() {
		SysUserModel model =getModel(SysUserModel.class) ;
		String salt = ShiroEncryption.salt();
		if(StringUtils.isEmpty(model.getStr("id"))) {
			model.setPassword(ShiroEncryption.shaSaltPassWord(model.getPassword(), salt));
			model.setSalt(salt);
			model.setCreateTime(new Timestamp(System.currentTimeMillis()));
			model.save();
		}else {
			model.setPassword(ShiroEncryption.shaSaltPassWord(model.getPassword(), salt));
			model.setSalt(salt);
			model.setUpdateTime(new Timestamp(System.currentTimeMillis()));
			model.update();
		}
		setAttr("msg","ok");
		renderJson();
	}
	
	public void edit() {
		
	}
	
	public void del() {
		
	}
}
